home *** CD-ROM | disk | FTP | other *** search
- Path: fang.dsto.defence.gov.au!usenet
- From: dpr@itd.dsto.gov.au (David Rajaratnam)
- Newsgroups: comp.lang.c++,comp.os.msdos.programmer
- Subject: 'interrupt' in Turbo C++
- Date: 12 Jan 1996 04:45:22 GMT
- Organization: Defence Science & Technology Organisation
- Distribution: world
- Message-ID: <4d4p12$67h@fang.dsto.defence.gov.au>
- Reply-To: dpr@itd.dsto.gov.au
- NNTP-Posting-Host: tcs17.dsto.gov.au
-
-
- Hi there,
- I hope I've got the right newsgroups for this question.
- I'm having problems writing an interrupt handler using
- Borland Turbo C++ v3 for DOS. The problem arises when
- I want the interrupt function to return results via
- the registers.
-
- Under C what I do is;
-
- typedef struct {
- int bp, di, si, ds, es, dx, cx, bx, ax, ip, cs, fl;
- } IREGS;
-
- static void interrupt (*mycinterrupt)(IREGS ir){
-
- <do stuff>
-
- ir.ax = _AX
- }
-
- I don't know how this works, but it does. Normally if you pass a value
- in the argument list changing it is doesn't pass back the original
- value - that's what pointers are for! However I presume this is
- a messy (counter intuitive) workaround to allow register values
- to be changed, since declaring a function as 'interrupt' should
- save and restore ALL registers on return so what ever values
- saved to registers inside the function are lost.
-
- Unfortunately, the declaration of setvect and getvect in C++
- does things a bit differently. I quote;
-
- Syntax
- void interrupt(*getvect(int interruptno))(); /*C version*/
- void interrupt(*getvect(int interruptno))(...); //C++ version
- void setvect(int interruptno, void interrupt (*isr)()); /*C version*/
- void setvect(int interruptno, void interrupt (*isr)(...)); //C++ version
-
- So making the call setvect(0xXX, mycinterrupt) will give me a
- compiler error now. To get around this what I tried to do was;
-
- static void interrupt (*mycppinterrupt)(...){
- IREGS *ir;
-
- <do stuff>
-
- ir = (IREGS *)...;
- ir->ax = _AX;
- }
-
- Although this version compilied, when run the results where
- not what I was hoping for. I also tried using the <stdarg.h>
- stuff but they gave me the same results as above. I can only
- guess that what C++ expects to see is different to the
- C version. Unfortunately nowhere in the Documentation (that
- I can find), or other books I own, does it describe what
- C++ expects. Mind you the arguments of the C version were
- not adequately described either, it's just that I happened
- to come across an example that used the
- tydef struct { bp, ...} IREGS method.
-
-
- If anyone could provide a solution or a pointer to books that
- might be useful I would greatly appreciate it. (An explanation
- of what C does as well, in terms of argument lists, when a
- function is declared as 'interrupt' would also be handy)
-
- Thanks in advance,
-
- Dave Rajaratnam
-
-
-